var UId = getParameter("UId");
var now = new Date();
$(function() {
	charts(now);
});
function charts(now) {
	var urlStr = serverPath + "/app/doctor/diabetes/weightView.do";
	var jsonStr = '{method:"showWeightChart",UId:"' + UId + '",befdate:"'
			+ getLastDay(now, 3).format("yyyy-MM-dd") + '",aftdate:"'
			+ getNextDay(now, 3).format("yyyy-MM-dd") + '",day:"7"}';
	UseAjax(urlStr, jsonStr, document.cookie, rt, '1');
}
function rt(data) {
	var datas = new Array();
	var wi = data.records;
	if (wi.length > 0) {
		for (var int = 0; int < wi.length; int++) {
			datas[int] = [
					Date.UTC(wi[int].dates.substring(0, 4), wi[int].dates
							.substring(5, 7) - 1,
							wi[int].dates.substring(8, 10), wi[int].dates
									.substring(11, 13)), Number(wi[int].value) ];

		}
	}
	$('#container').highcharts(
			{

				title : {
					text : ''
				},
				subtitle : {
					text : getLastDay(now, 3).format("yyyy-MM-dd")+" 到 "+getNextDay(now, 3).format("yyyy-MM-dd")
				},
				xAxis : {
					type : 'datetime',
					dateTimeLabelFormats : {
						second : '%H:%M:%S',
						minute : '%H:%M',
						hour : '%H:%M',
						day : '%m-%d',
						week : '%m-%d',
						month : '%m',
						year : '%Y'
					},
					min : Date.UTC(now.getFullYear(), now.getMonth(), now
							.getDate() - 3),
					max : Date.UTC(now.getFullYear(), now.getMonth(), now
							.getDate() + 3),
					maxPadding : 5,
					gridLineWidth : 1,
					gridLineDashStyle : 'Dash',// 样式 虚线

				},
				yAxis : {
					min : 20, // 固定列最小值
					max : 150,
					title : {
						align: 'high',
		                offset: 10,
		                text: 'KG',
		                rotation: 0,
		                y: -10
					},
					labels : {
						formatter : function() {
							return "" + this.value ;
						}
					} 
					,
				},
				tooltip : {
					formatter : function() {
					}
				},
				plotOptions : {
					line : {
						dataLabels : {
							enabled : true
						},
						enableMouseTracking : false
					}
				},
				credits : {
					enabled : false
				},
				legend : {
					enabled : false
				},
				series : [ {
					pointPadding : 0,// 数据点之间的距离值
					groupPadding : 0,// 分组之间的距离值
					name : null,
					data : datas
				} ]
			});
}

$(function() {
	// swipe 的dome
	$("#container").swipe(
			{
				swipeLeft : function(event, direction, distance, duration,
						fingerCount) {
					now = getNextDay(now, 7);
					charts(now);
				},
				swipeRight : function(event, direction, distance, duration,
						fingerCount) {
					now = getLastDay(now, 7);
					charts(now);
				},
			});

});
